package com.yidu.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;

import org.apache.ibatis.builder.annotation.MapperAnnotationBuilder;
import org.springframework.stereotype.Service;

import com.yidu.dao.LockerTbMapper;
import com.yidu.model.LockerTb;
import com.yidu.service.TbService;
import com.yidu.util.Pages;

/**
 *  服务实现类
 * @author ly
 * @since 2018-10-20
 */
@Service
public class TbServiceImpl implements TbService {
	@Resource
	private LockerTbMapper Mapper;
	/**
	 * 查询
	 */
	@Override
	public List<LockerTb> findAll(LockerTb tb,Pages pages) {
		Map<String, Object> map=new HashMap<>();
		map.put("tb", tb);
		map.put("pages", pages);
		return Mapper.selectAll(map);
	}
	
	/**
	 * 增加修改
	 */
	@Override
	public int addOrUpdate(LockerTb tb) {
		if(tb.getLocId()!=null && !"".equals(tb.getLocId())) {
			return Mapper.updateByPrimaryKeySelective(tb);
		}else {
			String uuid=UUID.randomUUID().toString().replaceAll("-", "");
			tb.setLocId(uuid);
			return Mapper.insertSelective(tb);
		}
	}

	/**
	 * 删除
	 */
	@Override
	public int delete(String locId) {
		return Mapper.deleteByPrimaryKey(locId);
	}
	
	/**
	 * 修改的上屏
	 */
	@Override
	public LockerTb findById(String tbId) {
		LockerTb tb= Mapper.selectByPrimaryKey(tbId);
		return tb;
	}
	/**
	 * 分页
	 */
	@Override
	public int findCount2(LockerTb tb) {
		int rows=Mapper.findCount2(tb);
		return rows;
	}
	
	@Override
	public List<LockerTb> selectTb() {
		return Mapper.selectTb();
	}
}